# Specify width of confidence intervals
interval1 <- -qnorm((1-0.9)/2)  # 90% multiplier
interval2 <- -qnorm((1-0.95)/2) # 95% multiplier

CoefPlot12 <- ggplot(dfIpl12Reg[5:11, ], aes()) +
  geom_hline(yintercept = 0, colour = gray(1/2), lty = 2) + 
  geom_linerange(aes(x = Variable, 
                     ymin = Coefficient - SE*interval1,
                     ymax = Coefficient + SE*interval1),
                 lwd = .7, colour = '#8da0cb') +
  geom_pointrange(aes(x = Variable,
                      y = Coefficient, 
                      ymin = Coefficient - SE*interval2, 
                      ymax = Coefficient + SE*interval2), 
                  size = .4, fatten = 1.5, shape = 21, colour = '#8da0cb', fill = '#8da0cb') +
  scale_x_discrete(labels = c("immiFactorcitizenNat" = "Naturalized", 
                              "immiFactorGreenCard_EU" = "Permanent \n Resident",
                              "yearsInStd" = "Residency \n (+1SD; 19y)",
                              "sharedL" = "Shared \n Language",
                              "yschoolingStd" = "Education \n (+1SD; 5y)",
                              "gender" = "Female",
                              "ageStd" = "Age \n (+1SD; 18y)")) +
  xlab("") +
  ylab("Change in IPL-12 Integration Index") +
  ggtitle("") +
  coord_flip() +
  theme_minimal() +
  theme(axis.line.x = element_line(colour = "black", 
                                   size = 1/2, linetype = "solid"),
        axis.ticks.length = unit(.2, "cm"),
        axis.ticks.x = element_line(size = .8),
        axis.title = element_text(size = 8),
        axis.text = element_text(size = 7),
        plot.title = element_text(size = 8),
        legend.position = "none",
        plot.margin = margin(5.5, 22, 5.5, 5.5, "pt")) +
  scale_color_manual(values = Col3) +
  scale_fill_manual(values = Col3)


CoefPlot24 <- ggplot(dfIpl24Reg[5:11, ], aes()) +
  geom_hline(yintercept = 0, colour = gray(1/2), lty = 2) + 
  geom_linerange(aes(x = Variable, 
                     ymin = Coefficient - SE*interval1,
                     ymax = Coefficient + SE*interval1),
                 lwd = .7, colour = '#8da0cb') +
  geom_pointrange(aes(x = Variable,
                      y = Coefficient, 
                      ymin = Coefficient - SE*interval2, 
                      ymax = Coefficient + SE*interval2), 
                  size = .4, fatten = 1.5, shape = 21, colour = '#8da0cb', fill = '#8da0cb') +
  scale_x_discrete(labels = c("immiFactorcitizenNat" = "Naturalized", 
                              "immiFactorGreenCard_EU" = "Permanent Resident",
                              "yearsInStd" = "Residency \n (+1SD; 19y)",
                              "sharedL" = "Shared Language",
                              "yschoolingStd" = "Education \n (+1SD; 5y)",
                              "gender" = "Female",
                              "ageStd" = "Age \n (+1SD; 18y)")) +
  xlab("") +
  ylab("Change in IPL-24 Integration Index") +
  ggtitle("") +
  coord_flip() +
  theme_minimal() +
  theme(axis.line.x = element_line(colour = "black", 
                                   size = 1/2, linetype = "solid"),
        axis.ticks.length = unit(.2, "cm"),
        axis.ticks.x = element_line(size = .8),
        axis.title = element_text(size = 9),
        axis.text = element_text(size = 8),
        plot.title = element_text(size = 9),
        legend.position = "none") +
  scale_color_manual(values = Col3) +
  scale_fill_manual(values = Col3)

ggsave(here::here("Draft/PNAS/draft/plots", "coefPlot12.pdf"), plot = CoefPlot12)
ggsave(here::here("Draft/PNAS/draft/plots", "coefPlot24.pdf"), plot = CoefPlot24)
